-- Lua Empires
-- All of the example materials are should be used as their own licences. 
-- We are not giving them with GPLv3
-- These example files are got from löve2d's forums and Tiled's example folder
-- They are not going to be part of this project!

love.filesystem.load("tiledmap.lua")()

img = love.graphics.newImage("walk-right-villager.png")
villager = { }
villager[2] = love.graphics.newQuad(2,2,140,250,1024,256)
villager[3] = love.graphics.newQuad(144,2,140,250,1024,256)
villager[1] = love.graphics.newQuad(286,2,140,250,1024,256)
villager[4] = love.graphics.newQuad(428,2,140,250,1024,256)


-- 3 1 2 4
index = 0
function love.load()
     	TiledMap_Load("map01.tmx")

   player = {
        grid_x = 128,
        grid_y = 128,
        act_x = 64,
        act_y = 64,
        speed = 10,
   }  
end

function love.update(dt)
      player.act_y = player.act_y - ((player.act_y - player.grid_y) * player.speed * dt)
      player.act_x = player.act_x - ((player.act_x - player.grid_x) * player.speed * dt)
end

function love.draw()
    TiledMap_DrawNearCam(love.mouse.getX( ),love.mouse.getY( ))
    love.graphics.scale(0.28, 0.28)   
    if index%5 == 0 then
        index = index + 1
    end
    love.graphics.drawq(img, villager[index%5], player.act_x, player.act_y)
    love.graphics.pop()


end

function love.keypressed(key)
    if key == "right" then
        index = index + 1
        player.grid_x = player.grid_x + 32
    elseif key == "left" then
        index = index + 1
        player.grid_x = player.grid_x - 32

    end
end

-- Personal Math
function minL(x)
  min=x[1]
  for i=2,#x do
    if x[i]<min then
      min=x[i]
    end
  end
  return min
end

